package com.example.forum.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Autowired
    private HandlerInterceptor handlerInterceptor;

    private final List excludes = Arrays.asList("/**/*.html",
                                                "/js/**",
                                                "/image/**",
                                                "/dist/**",
                                                "/user/register",
                                                "/user/login",
                                                "/swagger*/**",
                                                "/v3*/**");
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(handlerInterceptor)
                .excludePathPatterns(excludes)
                .addPathPatterns("/**");//拦截所有路径，除了excludes中的
    }
}
